package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.query.TravelQueryObject;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//大家都在看页面
@Controller
@RequestMapping("loop")
public class LoopAndLoop {
    @Autowired
    private ITravelService travelService;


    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo") TravelQueryObject qo) {
        model.addAttribute("result",travelService.queryForList(qo));
        return "loop/list";
    }
    //一个删除 一个添加
    @RequestMapping("save")
    @ResponseBody
    public JSONResult saveOrUpdate(Travel travel) {
        JSONResult result = new JSONResult();
        try {
            travelService.save(travel);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
    //一个删除 一个添加
    @RequestMapping("delete")
    @ResponseBody
    public JSONResult delete(Long id) {
        JSONResult result = new JSONResult();
        try {
            travelService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }











}
